﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BUS;
using DTO;

namespace GUI
{
    public partial class frmPhieuXuatKho : Form
    {
        public frmPhieuXuatKho()
        {
            InitializeComponent();
        }

        private void frmPhieuXuatKho_Load(object sender, EventArgs e)
        {
            try
            {
                int stt = 1;
                PhieuXuatKhoBUS pxkbus = new PhieuXuatKhoBUS();
                List<PhieuXuatKhoDTO> dspxk = new List<PhieuXuatKhoDTO>();
                dspxk = pxkbus.LayDanhSachPhieuXuatKho();
                for (int i = 0; i < dspxk.Count; i++)
                {
                    dgvDSPXK.Rows.Add(stt, dspxk[i].MaPhieuXK, dspxk[i].NgayLap, dspxk[i].MaNV, dspxk[i].TenNV,dspxk[i].MaPYC);
                    stt++;
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show("Lỗi:" + ex.ToString());
            }
            
        }

        public void hienthichitiet_PXK(int ma)
        {
            dgvChiTietPXK.Rows.Clear();
            CT_PhieuXuatKhoBUS ctpxk = new CT_PhieuXuatKhoBUS();
            List<CT_PhieuXuatKhoDTO> dsctpxk = new List<CT_PhieuXuatKhoDTO>();
            dsctpxk = ctpxk.LayDanhSachCTPhieuXuatKho(ma);

            int stt = 1;
            for (int i = 0; i < dsctpxk.Count; i++)
            {
                dgvChiTietPXK.Rows.Add(stt, dsctpxk[i].MaNVL, dsctpxk[i].Ten, dsctpxk[i].SoLuong, dsctpxk[i].DonViTinh, dsctpxk[i].Gia);
            }

        }

        private void dgvDSPXK_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }
            int intIndex = e.RowIndex;
            dgvDSPXK.Rows[intIndex].Selected = true;
            //Load Chi Tiết
            int dong = dgvDSPXK.SelectedCells.Count;
            if (dong == 0)
                return;
            dong = dgvDSPXK.SelectedCells[0].RowIndex;
            try
            {
                int ma = int.Parse(dgvDSPXK.Rows[dong].Cells[0].Value.ToString());
                hienthichitiet_PXK(ma);
            }
            catch (Exception)
            {
                return;
            }
        }

        private void buttonX4_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            frmThemPhieuXuatKho fr = new frmThemPhieuXuatKho();
            fr.ShowDialog();
        }

        private void panelEx1_Click(object sender, EventArgs e)
        {

        }
    }
}
